﻿''' <summary>
''' 定义的地图抽象类
''' </summary>
Public MustInherit Class CMap
    ''' <summary>
    ''' 访问时所需要的Cookie
    ''' </summary>
    Public cookies As New Sy.Net.CookieContainer
    ''' <summary>
    ''' 更新UI窗体显示
    ''' </summary>
    Public UpdateView As Action(Of CProductInfo)
    ''' <summary>
    ''' Task从UI窗体传入
    ''' </summary>
    Public task As Model_Task
    ''' <summary>
    ''' 默认从资源文件中读取城市的Code码
    ''' </summary>
    ''' <param name="area">城市名称</param>
    ''' <returns></returns>
    Public Overloads Function GetCode(area As String) As String
        Dim txt = My.Resources.districts, spliter = """: """ & area
        Dim region = Split(txt, spliter)(0)
        Return region.Substring(region.LastIndexOf("""") + 1)
    End Function
    ''' <summary>
    ''' 采集过滤
    ''' </summary>
    ''' <param name="phone">固定电话</param>
    ''' <param name="mobile">手机号</param>
    ''' <param name="address">地址</param>
    ''' <returns></returns>
    Public Function FilterResult(title As String, phone As String, mobile As String, address As String) As Boolean
        Dim exportStr = $"[数据]:{title},{address},{phone}"
        If exportStr.Length > 15 Then exportStr = exportStr.Substring(0, 15)
        Log($"[数据]:{exportStr}......")
        Select Case task.Filter
            Case Filter.Mobile
                Return PhoneReg.IsMatch(phone & mobile)
            Case Filter.None
                Return True
            Case Filter.Some
                Return phone.Length > 0 OrElse mobile.Length > 0 'Or address.Length > 0
            Case Else
                Throw New ArgumentOutOfRangeException("task.Filter")
        End Select
    End Function
    Public Function FilterKeywordResult(Title As String, Filiter As List(Of CFilterKeyword)) As Boolean
        For Each item In Filiter
            If Title.Contains(item.FilterKeyword) Then Return False
        Next
        Return True
    End Function
End Class
''' <summary>
''' 地图数据采集主方法
''' </summary>
Public Interface IMap
    Sub Deal()
End Interface


